fbfbeb3aac33393d81b98fe5e9564b500d6c07b4,app/src/main/java/com/google/developer/udacityalumni/service/AlumIntentService.java,AlumIntentService,addArticles,#String#,40
Before Change
ContentValues values = new ContentValues();
int isSpotlighted = article.getBoolean(KEY_SPOTLIGHTED) ? 1 : 0;
JSONObject user = article.getJSONObject(KEY_USER);
JSONArray tags = article.getJSONArray(KEY_TAGS);
int ind = new Random().nextInt(tags.length());
JSONObject tag = tags.getJSONObject(ind);
values.put(AlumContract.ArticleEntry.COL_ARTICLE_ID, articleId);
After Change
ContentValues values = new ContentValues();
int isSpotlighted = article.getBoolean(KEY_SPOTLIGHTED) ? 1 : 0;
JSONObject user = article.getJSONObject(KEY_USER);
Object tagObjects = article.get(KEY_TAGS);
if (tagObjects != null && tagObjects instanceof JSONArray && ((JSONArray) tagObjects).length() > 0){
JSONArray tags = (JSONArray) tagObjects;
int ind = new Random().nextInt(tags.length());
JSONObject tag = tags.getJSONObject(ind);
values.put(AlumContract.ArticleEntry.COL_RANDOM_TAG_ID, tag.getLong("id"));